package com.wanmait.recruit.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recruit.mapper.CompanyPositionMapper;
import com.wanmait.recruit.pojo.City;
import com.wanmait.recruit.pojo.Company;
import com.wanmait.recruit.pojo.CompanyPosition;
import com.wanmait.recruit.pojo.Person;
import com.wanmait.recruit.service.CompanyPositionService;
import com.wanmait.recruit.util.PageContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("companyPositionService")
@Transactional(rollbackFor = Exception.class)
public class CompanyPositionServiceImpl implements CompanyPositionService {

    @Resource
    CompanyPositionMapper companyPositionMapper;

    @Override
    public void insert(CompanyPosition object) {
        companyPositionMapper.insertSelective(object);
    }

    @Override
    public void delete(CompanyPosition object) {

    }

    @Override
    public void update(CompanyPosition object) {

    }

    @Override
    public PageInfo<CompanyPosition> search(int pageNum, int pageSize) {
        return null;
    }
    @Override
    public PageInfo<CompanyPosition> searchRes(int pageNum, int pageSize,CompanyPosition companyPosition) {
        PageHelper.startPage(pageNum,pageSize);
        List<CompanyPosition> companyPositions = companyPositionMapper.searchRes(companyPosition);
        PageInfo<CompanyPosition> pageInfo = new PageInfo<>(companyPositions);
        return pageInfo;
    }

    @Override
    public PageInfo<CompanyPosition> searchByCompanyOrPosition(String positionOrCompanyName,String selectedPosition) {
        int pageNum = PageContext.getPageNum();
        int pageSize= 10;
        PageHelper.startPage(pageNum,pageSize);
        List<CompanyPosition> companyPositions = companyPositionMapper.searchByCompanyOrPosition(positionOrCompanyName,selectedPosition);
        PageInfo<CompanyPosition> pageInfo = new PageInfo<>(companyPositions);
        return pageInfo;
    }

    @Override
    public PageInfo<CompanyPosition> searchBySomeId(Integer industryId, Integer typeId, Integer positionId, Integer pageNum) {
        //int pageNum = PageContext.getPageNum();
        int pageSize= 10;
        PageHelper.startPage(pageNum,pageSize);
        List<CompanyPosition> companyPositions = companyPositionMapper.searchBySomeId(industryId,typeId,positionId);
        PageInfo<CompanyPosition> pageInfo = new PageInfo<>(companyPositions);
        return pageInfo;
    }

    @Override
    public PageInfo<CompanyPosition> searchByIndustryId(Integer industryId, Integer pageNum) {
        int pageSize= 10;
        PageHelper.startPage(pageNum,pageSize);
        List<CompanyPosition> companyPositions = companyPositionMapper.searchByIndustryId(industryId);
        PageInfo<CompanyPosition> pageInfo = new PageInfo<>(companyPositions);
        return pageInfo;
    }

    @Override
    public PageInfo<CompanyPosition> searchByTypeId(Integer typeId, Integer pageNum) {
        int pageSize= 10;
        PageHelper.startPage(pageNum,pageSize);
        List<CompanyPosition> companyPositions = companyPositionMapper.searchByTypeId(typeId);
        PageInfo<CompanyPosition> pageInfo = new PageInfo<>(companyPositions);
        return pageInfo;
    }

    @Override
    public PageInfo<CompanyPosition> searchByPositionId(Integer positionId, Integer pageNum) {
        int pageSize= 10;
        PageHelper.startPage(pageNum,pageSize);
        List<CompanyPosition> companyPositions = companyPositionMapper.searchByPositionId(positionId);
        PageInfo<CompanyPosition> pageInfo = new PageInfo<>(companyPositions);
        return pageInfo;
    }

    @Override
    public void deleteByPersonId(Integer id) {
        companyPositionMapper.deleteByPersonId(id);
    }

    @Override
    public PageInfo<CompanyPosition> findByCompany(Company company) {
        PageHelper.startPage(PageContext.getPageNum(),4);
        List<CompanyPosition> companyPositions = companyPositionMapper.findByCompanyId(company.getId());
        PageInfo<CompanyPosition> pageInfo = new PageInfo<>(companyPositions);

        return pageInfo;
    }

    @Override
    public List<CompanyPosition> findByHr(Person person, Company company) {
        return companyPositionMapper.findByHr(person.getId(),company.getId());
    }

    @Override
    public List<CompanyPosition> findByAdmin(Company company) {
        return companyPositionMapper.findByAdmin(company.getId());
    }

    @Override
    public void updatePosition(CompanyPosition companyPosition) {
        companyPositionMapper.updateByPrimaryKeySelective(companyPosition);
    }

    @Override
    public void updateEnable(Integer id) {
        companyPositionMapper.updateEnable(id);
    }

    @Override
    public CompanyPosition findById(Integer id) {
        return companyPositionMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<CompanyPosition> findAll() {
        return companyPositionMapper.findAll();
    }
}
